//
//  BaseViewController.m
//
//  Created by Northwan on 15/4/12.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司.. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()
@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //所有页面统一的背景色
    [self.view setBackgroundColor:PUBLIC_BG];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    //处理NavigationBar遮盖页面头部
    if ([self shouldAdjustEdge]) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    //处理需要登录且没有登录的时候弹出登陆界面
    if([self shouldLogin]){
        if(!ISLOGIN){
            [Utils showLoginCtrl:self.navigationController.viewControllers.lastObject];
        }
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [TalkingData trackPageBegin:NSStringFromClass([self class])];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [TalkingData trackPageEnd:NSStringFromClass([self class])];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //是否要改变statusBar的颜色
    if([self shouldStatusBarLightContent]){
          [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }else{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    }
    
    //是否要隐藏状态栏
    if([self shouldHideStatusBar]){
        UIApplication *app = [UIApplication sharedApplication];
        [app setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
    }
}

-(BOOL)shouldStatusBarLightContent{
    return NO;
}

-(BOOL)shouldAdjustEdge{
    return YES;
}

-(BOOL)shouldLogin{
    return NO;
}

-(BOOL)shouldHideStatusBar{
    return NO;
}

@end
